<?php
namespace jy_weishop;
defined('BY_JYA') or exit('error');
/*
	购物车
*/
class cart extends \plugin{
	public function getall($selected='',$merchid=''){
		$params=array('mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']);
		if($selected){
			$params['selected']=1;
		}
		$carts = pdo_getall('jy_weishop_member_cart',$params);
		$goodsprice=0;
		foreach($carts as $k=>&$cv){
			$goods=array('id'=>$cv['goodsid'],'price'=>$cv['price'],'optionid'=>$cv['optionid'],'storeid'=>$cv['storeid']);
			$goods=$this->model('activity')->get_upgoods($goods);
			$cv['goodstotal']=intval($goods['total']);
			$cv['active']=$goods['active'];
			$cv['price']=$cv['active']['price']?:$cv['price'];
			$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$cv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('title','pcate','total','unit','merchid'));
			if($merchid && $goodsinfo['merchid']!=$merchid){
				unset($carts[$k]);
				continue;
			}
			$goodsprice +=$cv['price']*$cv['total'];
			$cv['title']=$goodsinfo['title'];
			$cv['pcate']=$goodsinfo['pcate'];
			$cv['unit']=$goodsinfo['unit'];
			$cv['weight']=$this->pdo_getcolumn('goods_dispatch',array('goodsid'=>$cv['goodsid']),'weight');
			if($cv['optionid']){
				$cv['options']=pdo_get('jy_weishop_goods_option',array('id'=>$cv['optionid']),array('id','stock','specs'));
				//规格
				$specids = explode("_", $cv['options']['specs']);
				$selespename = '';
				if($specids){
						foreach($specids as $k=>$sp){
							$spec_item=pdo_get('jy_weishop_goods_spec_item',array('id'=>$sp,'uniacid'=>$_SESSION['uniacid']),array('id','title'));
							$selespename .=$spec_item['title'].'，';
						}
				}
				$cv['optiontitle']= $selespename;
			}
		}
		$return['list']=$carts;
		$return['goodsprice']=$goodsprice;
		return $return;
	}
	
}